package com.orange.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.orange.domain.User;
import com.orange.dto.UserDto;
import com.orange.mapper.UserMapper;
import com.orange.service.UserService;
import com.orange.utils.MD5Util;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(User record) {
        record.setPassword(MD5Util.md5(record.getPassword()));
        record.setCreateTime(new Date());
        record.setUpdateTime(new Date());
        record.setDeleted(1);
        return userMapper.insert(record);
    }

    @Override
    public int insertSelective(User record) {
        return userMapper.insertSelective(record);
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }

    @Override
    public User login(String username, String password) {
       return userMapper.login(username,password);
    }

    @Override
    public PageInfo<User> queryUserByPage(UserDto userDto) {
        Page<User> page = PageHelper.startPage(userDto.getPage(), userDto.getLimit());
        List<User> userList=userMapper.queryAllUser(userDto);
        return page.toPageInfo();
    }

    @Override
    public List<User> queryAvailableUser() {
        List<User> userList = userMapper.queryAvailableUser();
        return userList;
    }

    @Override
    public List<String> queryEmail(List<Integer> id) {
        return userMapper.queryEmail(id);
    }

}
